package com.example.administrator.foodrowfresh.views;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.example.administrator.foodrowfresh.R;
import com.example.administrator.foodrowfresh.adapter.SeekGridViewAdapter;
import com.example.administrator.foodrowfresh.classfile.JsonParserHomePage;
import com.example.administrator.foodrowfresh.configs.HomepageConfig;
import com.example.administrator.foodrowfresh.models.ClassifySeek;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class FirstTopSeek extends AppCompatActivity {

    private GridView mGridView;
    private List<ClassifySeek.DataBean> dataBeans;
    private SeekGridViewAdapter gridViewAdapter;
    private Callback.Cancelable cancelable;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first_top_seek);
        initView();
    }
    public void initView()
    {
        mGridView= (GridView) findViewById(R.id.classify_gridview_id);
        dataBeans=new ArrayList<>();

        gridViewAdapter=new SeekGridViewAdapter(dataBeans,this);
        mGridView.setAdapter(gridViewAdapter);

        downloud(HomepageConfig.SEEK_PATH);

    }
    public void downloud(String path)
    {
        RequestParams params=new RequestParams(path);
        cancelable = x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                List<ClassifySeek.DataBean> list = JsonParserHomePage.parserJsonSeek(result);
                dataBeans.addAll(list);
                gridViewAdapter.notifyDataSetChanged();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //收索
    public void onSelect(View view) {

    }

    /*
    * 返回
    * */
    public void onBack(View view) {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        cancelable.cancel();
    }
}
